package entities;

import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;

/**
 *
 * @author casshern
 */
public abstract class GameObject {

    public final static int NONE = 0;
    public final static int MINER = 1;//MINER ASTEROID
    public final static int ATTACK = 2;//HIRE THIS TO ATTACK OTHERS
    public final static int POWERSTATION = 3;//JI DI
    public final static int LASER = 4;//TO DEFENCE
    public final static int ASTEROID0 = 5;// asteroid part
    public final static int ASTEROID1 = 6;
    public final static int ASTEROID2 = 7;
    public final static int ASTEROID3 = 8;
    public final static int BACKGROUNDIMAGE = 9;
   
    protected int x, y;
    protected int type;
    protected boolean alive;
    protected int size;
    protected int range;
    protected int currentHealth;
    protected int maxHealth;
    protected int playerID;

    public abstract void drawObject(Graphics2D g);

    public void decHealth() {
        if (!alive) {
            return;
        }
        currentHealth--;
        if (currentHealth <= 0) {
            currentHealth = 0;
            alive = false;
        }
    }

    public void decHealth(int pain) {
        if (!alive) {
            return;
        }
        currentHealth = currentHealth - pain;
        if (currentHealth <= 0) {
            currentHealth = 0;
            alive = false;
        }
    }

    public Shape getBound() {
        return new Ellipse2D.Double(x, y, size, size);
    }

    public Property getProperty() {
        return new Property(playerID, type, x, y, currentHealth, alive);
    }

    public boolean contains(int x, int y) {
        if (x > this.x && x < this.x + size && y > this.y && y < this.y + size && alive) {
            return true;
        }
        return false;
    }

    public boolean isInRange(Shape shape) {
        Area rangeArea = new Area(new Ellipse2D.Double(x - (range - size) / 2, y - (range - size) / 2, range, range));
        Area inter = new Area(shape);
        inter.intersect(rangeArea);
        if (!inter.isEmpty()) {
            return true;
        }
        return false;
    }

    public void setPlayerID(int value) {
        playerID = value;
    }

    public int getPlayerID() {
        return playerID;
    }

    public boolean isAlive() {
        return alive;
    }

    public int getCurrentHealth() {
        return currentHealth;
    }

    public int getMaxHealth() {
        return maxHealth;
    }

    public int getRange() {
        return range;
    }

    public int getSize() {
        return size;
    }

    public int getType() {
        return type;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }
}
